﻿Imports Business

Public Class frmGroupManager


    Public strServer As String
    Public Sub New(ByVal strSv As String)

        strServer = strSv
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Dim bsGroup As New BSGroup(strServer)
        grdGroupManager.DataSource = bsGroup.GetAllGroup()

    End Sub

    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        Dim bsGroup As New BSGroup(strServer)
        If (bsGroup.InsertGroup(nudGroupID.Value, txtGroupName.Text) = 1) Then
            grdGroupManager.DataSource = bsGroup.GetAllGroup()
        Else
            MsgBox("Insert is not successfull")
        End If
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim bsGroup As New BSGroup(strServer)
        If (bsGroup.DeleteGroup(nudGroupID.Value) = 1) Then
            grdGroupManager.DataSource = bsGroup.GetAllGroup()
        Else
            MsgBox("Delete is not successfull")
        End If
    End Sub

    Private Sub btnCancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub grdGroupManager_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdGroupManager.CellClick
        If grdGroupManager.Rows.Count <> 0 Then
            nudGroupID.Value = grdGroupManager.CurrentRow.Cells(0).Value
            txtGroupName.Text = grdGroupManager.CurrentRow.Cells(1).Value
        End If
    End Sub
End Class